<template>
  <div class="info-item">
    <div class="info-title">
      <span class="toggle-icon" @click="toggleShow">
        <el-icon :class="{ rotate: !show }">
          <arrow-down-bold />
        </el-icon>
      </span>
      <span>{{ title }}</span>
    </div>
    <el-collapse-transition>
      <div v-show="show" class="info-content">
        <slot></slot>
      </div>
    </el-collapse-transition>
  </div>
</template>

<script lang="ts" setup>
import { defineEmits, defineProps, ref } from 'vue'
defineProps({
  title: {
    type: String,
    default: '',
  },
})
const show = ref(true)
const emits = defineEmits(['toggle'])
const toggleShow = () => {
  show.value = !show.value

  setTimeout(() => {
    emits('toggle', show.value)
  }, 500)
}
</script>

<style lang="scss" scoped>
.info-title {
  display: flex;
  height: 40px;
  margin: 10px 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  align-items: center;
  border-bottom: 1px solid var(--table-border);
}

.toggle-icon {
  display: flex;
  width: 14px;
  height: 14px;
  margin-right: 10px;
  cursor: pointer;
  border: 1px solid #333;
  border-radius: 2px;
  align-items: center;
  justify-content: center;

  .el-icon {
    font-size: 10px;

    &.rotate {
      transform: rotate(-90deg);
    }
  }
}

.info-content {
  padding-left: 30px;
}
</style>
